package testcase;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Created by lzy.clement on 2017/7/7.
 */
public class ApplicationConfig {

    private final static Logger logger = LoggerFactory.getLogger(ApplicationConfig.class);

    private static PropertiesConfiguration properties;

    static {
        load();
    }

    private static void load() {
        properties = new PropertiesConfiguration();
        InputStream inputStream = null;

        try {
            File propertiesFile = new File("param.properties");
            if (!propertiesFile.exists()) {
                inputStream = new ClassPathResource("param.properties").getInputStream();
            } else {
                inputStream = new FileInputStream(propertiesFile);
            }

            properties.load(inputStream);

        } catch (Exception e) {
//            logger.error("load config error", e);
            System.out.println("load config error"+e);
//            System.exit(0);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static PropertiesConfiguration getProperties() {
        return properties;
    }

}

